package com.culturalCenter.dataCenter.service.impl.user;

import com.culturalCenter.dataCenter.entity.user.UserFootrpintCount;
import com.culturalCenter.dataCenter.mapper.user.UserFootrpintCountMapper;
import com.culturalCenter.dataCenter.service.user.UserFootrpintCountService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
 * UserFootprintCount业务层接口实现类
 */
@Service
public class UserFootrpintCountServiceImpl implements UserFootrpintCountService {

    @Resource
    private UserFootrpintCountMapper userFootrpintCountMapper;

    @Override
    public PageInfo<UserFootrpintCount> findPage(int page, int size) {
        return PageHelper.startPage(page, size).doSelectPageInfo(() -> userFootrpintCountMapper.findPageAll());
    }

    @Override
    public Integer delete(String id) {
        return userFootrpintCountMapper.deleteById(id);
    }

    @Override
    public Integer update(UserFootrpintCount userFootrpintCount) {
        return userFootrpintCountMapper.update(userFootrpintCount);
    }

    @Override
    public Integer add(UserFootrpintCount userFootrpintCount) {
        return userFootrpintCountMapper.insert(userFootrpintCount);
    }

    @Override
    public UserFootrpintCount findById(String id) {
        return userFootrpintCountMapper.queryById(id);
    }

    @Override
    public List<UserFootrpintCount> findAll(UserFootrpintCount userFootrpintCount) {
        return (List<UserFootrpintCount>) userFootrpintCountMapper.queryAll(userFootrpintCount);
    }

    @Override
    public UserFootrpintCount findByUserId(String userId) {
        UserFootrpintCount userFootprintCount = userFootrpintCountMapper.findByUserId(userId);
        return Optional.ofNullable(userFootprintCount).orElse(new UserFootrpintCount());
    }

}
